 package pool.tablename;



import java.util.Hashtable;
import java.util.Vector;

import pool.preprocess.Preprocess;

import basicprocess.Basicprocess;

//import pool.process.Process;

import control.RequestParameter;
//import utility.*; 
import database.RecordSearch;
import dbmanager.Column;
import dbmanager.DBManager;
import dbmanager.GetIdName;

/**
 * @author {@link SubPool} which is abstract class and implements Pool interface. 
 * Which is super class and inherited by master_table, property_details, trasaction, transaction_details,
 * trans_property_details, td_property_details classes.
 * */
public abstract class SubPool implements Pool
{
		public String Result,username,version,Request,process,message,password,table,productName;	
		public StringBuffer sbrDTB = new StringBuffer();
		boolean eventResult = false;
		
		public DBManager sqlDB;
		GetIdName gin;
		
	    String strID;
	    SubPool subObject;	
	    
	    public abstract StringBuffer getInsert();
		public abstract StringBuffer getUpdate();
		public abstract StringBuffer getView(); 
		String type="";

		public abstract StringBuffer getDelete(); 
		boolean flagResult = false;
		
		Hashtable<Object, Object> ErrorMap = new Hashtable<Object, Object>();
		RequestParameter reqParam;
	


	
	public void setDatabase(DBManager sqlDB)
	{
		this.sqlDB = sqlDB;
		gin=new GetIdName(sqlDB);
	}
	
	
	 public void setRequestParameter(RequestParameter reqParam)
	 {
		 	this.reqParam = reqParam;
			version = reqParam.getVersion();
			Request= reqParam.getRequest();
			process = reqParam.getProcess();
			message = reqParam.getMessage();
			password = reqParam.getPassword();
			username= reqParam.getUsername();
			productName = reqParam.getProductName();
	 }
	
	 public void setobject(SubPool subObject)
	 {
		 this.subObject=subObject;
	 }	
	
	
	
	public String getId() 
	{
		return strID;
	}
	public boolean getResult() 
	{
		return flagResult;
	}
	
		
	public RequestParameter getRequestParameter()
	{
		
	 return reqParam;
	}
	public Hashtable<Object, Object> process()
	{		
		Hashtable<Object, Object> error=new Hashtable<Object, Object>();
		try {
			Basicprocess basicprocess;
			error = new Hashtable<Object, Object>(); 
			//BASIC PROCESS LIKE INHERITANCE
			basicprocess = new Basicprocess();
			basicprocess.setDbmanager(sqlDB);
			basicprocess.setObject(this);
			basicprocess.processBasicprocess();
			basicprocess.getInsert();
			error = basicprocess.getHashtable();
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		if(!error.containsKey("ErrorInput"))
		{
			//PREPROCESS LIKE VALIDATION
			Preprocess preprocess = new Preprocess();
			preprocess.setDbmanager(sqlDB);
			preprocess.setObject(this);
			preprocess.ProcessPreprocess();
			error = preprocess.gethashtable();
		}
		System.out.println("The Error Hash Tabel :"+error);
		Hashtable<Object ,Object> ErrorMap=new Hashtable<Object, Object>();
		if(error.containsKey("ErrorInput"))
		{
			try 
			{
				ErrorMap.clear();
				Hashtable< Object, Object>TEMP = (Hashtable<Object, Object>) error.get("ErrorInput");
				System.out.println("The temp Map is  "+TEMP);
				System.out.println("The temp value Map is  "+TEMP.values());
				ErrorMap.put("ErrorInput",TEMP.values());
				System.out.println("The Error Map is  "+ErrorMap);
				return ErrorMap;
			}
			catch (Exception e) 
			{
				return error; 
			}
		}
		return ErrorMap;
	}	
		
	public Hashtable<Object,Object> getmasterHashtabel()
	{
		return new Hashtable<Object, Object>();
	}
	
	public void setmasterHashtabel(Hashtable<Object,Object> table)
	{
		
	}
	
	
	
	public void ProcessViewRequest()
	{
		String KEY="key";
		KEY = gin.getId(KEY);
		Hashtable<Object, Object> Condition = new Hashtable<Object, Object>();
		Condition.put("pid", KEY);
		Condition.put("pv", type);
		RecordSearch rs =new RecordSearch(sqlDB);
		rs.setConditionMap(Condition);
		String result[] = rs.getArrayFromResultSet();
		for(int i=0;i<result.length;i++)
		{
			Condition.clear();
			String splitresult[] = result[i].split("\t");
			Condition.put("mid",splitresult[Column.mid_index-1]);
			rs.setConditionMap(Condition);
			String line[] = rs.getArrayFromResultSet();
			for(int j=0;j<line.length;j++)
			{
				String splitline[] = line[i].split("\t");
				
			}
		}
	}
	
	public  void settplVector(Vector<Object>propertydetails)
	{
	}
	 public  Vector<Object> gettplVector()
	{
	   return new Vector<Object>(); 	 
	}
	
}
